<html>
<head><title>Test results</title>
<script src="jsonschema.js"></script>
<script>
var simpleObj = {
  "name" : "John Doe",
  "age" : 30,
  "schema" : {
    "name": {"type":"string",
       "required":true},
    "age" : {"type":"number",
      "maximum":125}
  }
}
var biggerObj = {
  "name" : "John Doe",
  "born" : "1979-03-23T06:26:07Z",
  "gender" : "mal",
  "address" : {"street":"123 S Main St",
    "city":33,//"Springfield",
    "state":"CA"}
  
}
var biggerSchema = {
    "name": {"type":"string",
	length:5,
      "required":true},
	  	"final":true,
    "born" : {"type":["number","string"], //allow for a numeric year, or a full date
      "format":"date", //format when a string value is used
      "minimum":1900, //min/max for when a number value is used
      "maximum":2010
    },
    "gender" : {"type":"string",
    "options":["male","female"]},
    "address" : {"type":
        {"street":{"type":"string"},
         "city":{"type":"string"},
         "state":{"type":"string"}},
       "format":"address"}
  }
window.onload = function() {
	showResults("simpleObj", JSONSchema.validate(simpleObj));
	showResults("biggerObj", JSONSchema.validate(biggerObj,biggerSchema));
	function showResults(testName, results) {
		if (results.length) { 
			resultsString = "Errors:";
			for (var i = 0; i < results.length; i++)
				resultsString += "<br/>Validation error for: " + results[i].property + " message: " + results[i].message
		 }		
		else
			resultsString = "Valid";
			document.body.appendChild(document.createElement('div')).innerHTML = testName + ": " + resultsString;
	}
}
</script>
<body>
<h2>Test results</h2>


</body></html>
